ThinkPHP5


think\model\Relation
library\think\model\Relation.php at line 20

Class Relation

Relation

public class Relation


Constant Summary
final static int

BELONGS_TO

final static int

BELONGS_TO_MANY

final static int

HAS_MANY

final static int

HAS_MANY_THROUGH

final static int

HAS_ONE

Constructor Summary
void

__construct(Model model)

架构函数

Method Summary
array|string|integer

getRelationInfo(string name)

获取当前关联信息

void

getRelation(mixed name)

array

eagerlyResultSet(array resultSet, string relation, string class)

预载入关联查询 返回数据集

protected mixed

resultSetBuild(array resultSet, string class)

封装关联数据集

Model

eagerlyResult(Model result, string relation, string class)

预载入关联查询 返回模型对象

protected void

match(string model, string relation, Model result)

一对一 关联模型预查询拼装

protected array

eagerlyOneToMany(object model, array where, string relation, string subRelation, bool closure)

一对多 关联模型预查询

protected array

eagerlyManyToMany(object model, array where, string relation, string subRelation)

多对多 关联模型预查询

$this

setAlias(array alias)

设置当前关联定义的数据表别名

$this

hasOne(string model, string foreignKey, string localKey, array alias, string joinType)

HAS ONE 关联定义

$this

belongsTo(string model, string foreignKey, string otherKey, array alias, string joinType)

BELONGS TO 关联定义

$this

hasMany(string model, string foreignKey, string localKey, array alias)

HAS MANY 关联定义

$this

hasManyThrough(string model, string through, string firstkey, string secondKey, string localKey, array alias, mixed foreignKey, mixed throughKey)

HAS MANY 远程关联定义

$this

belongsToMany(string model, string table, string foreignKey, string localKey, array alias)

BELONGS TO MANY 关联定义

protected \think\db\Query|string

belongsToManyQuery(object model, string table, string foreignKey, string localKey, array condition)

BELONGS TO MANY 关联查询

integer

save(mixed data, array pivot)

保存(新增)当前关联数据对象

integer

saveAll(array dataSet, array pivot)

批量保存当前关联数据对象

integer

attach(mixed data, array pivot)

附加关联的一个中间表数据

integer

detach(integer|array data, bool relationDel)

解除关联的一个中间表数据

Constant Detail

library\think\model\Relation.php at line 25

BELONGS_TO

public final static int BELONGS_TO = 3

library\think\model\Relation.php at line 26

BELONGS_TO_MANY

public final static int BELONGS_TO_MANY = 4

library\think\model\Relation.php at line 23

HAS_MANY

public final static int HAS_MANY = 2

library\think\model\Relation.php at line 24

HAS_MANY_THROUGH

public final static int HAS_MANY_THROUGH = 5

library\think\model\Relation.php at line 22

HAS_ONE

public final static int HAS_ONE = 1

Constructor Detail

library\think\model\Relation.php at line 56

__construct

public void __construct(Model model)

架构函数

Parameters:
model - 上级模型对象

Method Detail

library\think\model\Relation.php at line 67

getRelationInfo

public array|string|integer getRelationInfo(string name)

获取当前关联信息

Parameters:
name - 关联信息

library\think\model\Relation.php at line 82

getRelation

public void getRelation(mixed name)

library\think\model\Relation.php at line 137

eagerlyResultSet

public array eagerlyResultSet(array resultSet, string relation, string class)

预载入关联查询 返回数据集

Parameters:
resultSet - 数据集
relation - 关联名
class - 数据集对象名 为空表示数组

library\think\model\Relation.php at line 233

resultSetBuild

protected mixed resultSetBuild(array resultSet, string class)

封装关联数据集

Parameters:
resultSet - 数据集
class - 数据集类名

library\think\model\Relation.php at line 246

eagerlyResult

public Model eagerlyResult(Model result, string relation, string class)

预载入关联查询 返回模型对象

Parameters:
result - 数据对象
relation - 关联名
class - 数据集对象名 为空表示数组

library\think\model\Relation.php at line 308

match

protected void match(string model, string relation, Model result)

一对一 关联模型预查询拼装

Parameters:
model - 模型名称
relation - 关联名
result - 模型对象实例

library\think\model\Relation.php at line 334

eagerlyOneToMany

protected array eagerlyOneToMany(object model, array where, string relation, string subRelation, bool closure)

一对多 关联模型预查询

Parameters:
model - 关联模型对象
where - 关联预查询条件
relation - 关联名
subRelation - 子关联

library\think\model\Relation.php at line 360

eagerlyManyToMany

protected array eagerlyManyToMany(object model, array where, string relation, string subRelation)

多对多 关联模型预查询

Parameters:
model - 关联模型对象
where - 关联预查询条件
relation - 关联名
subRelation - 子关联

library\think\model\Relation.php at line 392

setAlias

public $this setAlias(array alias)

设置当前关联定义的数据表别名

Parameters:
alias - 别名定义

library\think\model\Relation.php at line 408

hasOne

public $this hasOne(string model, string foreignKey, string localKey, array alias, string joinType)

HAS ONE 关联定义

Parameters:
model - 模型名
foreignKey - 关联外键
localKey - 关联主键
alias - 别名定义
joinType - JOIN类型

library\think\model\Relation.php at line 431

belongsTo

public $this belongsTo(string model, string foreignKey, string otherKey, array alias, string joinType)

BELONGS TO 关联定义

Parameters:
model - 模型名
foreignKey - 关联外键
otherKey - 关联主键
alias - 别名定义
joinType - JOIN类型

library\think\model\Relation.php at line 454

hasMany

public $this hasMany(string model, string foreignKey, string localKey, array alias)

HAS MANY 关联定义

Parameters:
model - 模型名
foreignKey - 关联外键
localKey - 关联主键
alias - 别名定义

library\think\model\Relation.php at line 478

hasManyThrough

public $this hasManyThrough(string model, string through, string firstkey, string secondKey, string localKey, array alias, mixed foreignKey, mixed throughKey)

HAS MANY 远程关联定义

Parameters:
model - 模型名
through - 中间模型名
firstkey - 关联外键
secondKey - 关联外键
localKey - 关联主键
alias - 别名定义

library\think\model\Relation.php at line 503

belongsToMany

public $this belongsToMany(string model, string table, string foreignKey, string localKey, array alias)

BELONGS TO MANY 关联定义

Parameters:
model - 模型名
table - 中间表名
foreignKey - 关联模型外键
localKey - 当前模型关联键
alias - 别名定义

library\think\model\Relation.php at line 527

belongsToManyQuery

protected \think\db\Query|string belongsToManyQuery(object model, string table, string foreignKey, string localKey, array condition)

BELONGS TO MANY 关联查询

Parameters:
model - 关联模型对象
table - 中间表名
foreignKey - 关联模型关联键
localKey - 当前模型关联键
condition - 关联查询条件

library\think\model\Relation.php at line 545

save

public integer save(mixed data, array pivot)

保存(新增)当前关联数据对象

Parameters:
data - 数据 可以使用数组 关联模型对象 和 关联对象的主键
pivot - 中间表额外数据

library\think\model\Relation.php at line 572

saveAll

public integer saveAll(array dataSet, array pivot)

批量保存当前关联数据对象

Parameters:
dataSet - 数据集
pivot - 中间表额外数据

library\think\model\Relation.php at line 598

attach

public integer attach(mixed data, array pivot)

附加关联的一个中间表数据

Parameters:
data - 数据 可以使用数组、关联模型对象 或者 关联对象的主键
pivot - 中间表额外数据

library\think\model\Relation.php at line 633

detach

public integer detach(integer|array data, bool relationDel)

解除关联的一个中间表数据

Parameters:
data - 数据 可以使用关联对象的主键
relationDel - 是否同时删除关联表数据

ThinkPHP5